package com.wzt.lianfirecontrol.treeview.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wzt.lianfirecontrol.R;
import com.wzt.lianfirecontrol.bean.BaseModel;
import com.wzt.lianfirecontrol.bean.recode.user.MyTeamModel;
import com.wzt.lianfirecontrol.bean.recode.user.UserInfoModel;
import com.wzt.lianfirecontrol.treeview.model.BaseNodeViewHolder;
import com.wzt.lianfirecontrol.treeview.model.TreeNode;
import com.wzt.lianfirecontrol.utils.GildeUtils;
import com.wzt.lianfirecontrol.utils.ScreenUtils;
import com.wzt.lianfirecontrol.utils.StringUtils;
import com.wzt.lianfirecontrol.utils.Utils;

/**
 *
 */
public class IconTreeItemHolder extends BaseNodeViewHolder<BaseModel> {

    private Context context;

    private LinearLayout ll_item_content;
    private ImageView iv_my_team_img;
    private TextView tv_my_team_name;
    private ImageView iv_tel_icon;
    private LinearLayout ll_phone;
    private TextView tv_my_team_tele;

    public IconTreeItemHolder(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public View createNodeView(final TreeNode node, BaseModel value) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        final View view = inflater.inflate(R.layout.item_my_team, null);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.width = ScreenUtils.getScreenWidth(context);
        ll_item_content = view.findViewById(R.id.ll_item_content);
        ll_item_content.setLayoutParams(layoutParams);
        iv_my_team_img = view.findViewById(R.id.iv_my_team_img);
        tv_my_team_name = view.findViewById(R.id.tv_my_team_name);
        iv_tel_icon = view.findViewById(R.id.iv_tel_icon);
        ll_phone = view.findViewById(R.id.ll_phone);
        tv_my_team_tele = view.findViewById(R.id.tv_my_team_tele);
        if (value instanceof UserInfoModel){
            UserInfoModel userInfoModel = (UserInfoModel)value;
            if (StringUtils.isEmpty(userInfoModel.getImgUrl())){
                iv_my_team_img.setImageResource(R.mipmap.icon_my_team_img);
            }else {
                GildeUtils.loadImageCircle(context, iv_my_team_img, userInfoModel.getImgUrl());
            }
            tv_my_team_name.setText(userInfoModel.getRealName());
            tv_my_team_tele.setText(userInfoModel.getPhone());
            iv_tel_icon.setVisibility(View.VISIBLE);

            ll_item_content.setPadding(Utils.dip2px(context, 15 * userInfoModel.getTreeCount()), Utils.dip2px(context, 15),
                    Utils.dip2px(context, 15),Utils.dip2px(context, 15));
        }else if (value instanceof MyTeamModel){
            iv_my_team_img.setImageResource(R.mipmap.icon_my_team_img);
            ll_phone.setVisibility(View.GONE);
            MyTeamModel myTeamModel = (MyTeamModel)value;
            tv_my_team_name.setText(myTeamModel.getName());
            iv_my_team_img.setImageResource(R.mipmap.icon_my_team_company);
            iv_tel_icon.setVisibility(View.GONE);
            ll_item_content.setPadding(Utils.dip2px(context, 15 * myTeamModel.getTreeCount()), Utils.dip2px(context, 15),
                    Utils.dip2px(context, 15),Utils.dip2px(context, 15));
        }
        return view;
    }

    @Override
    public void toggle(boolean active) {
        // 伸缩

    }


}
